package org.gnyxy.controller.front;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.gnyxy.entity.Dish;
import org.gnyxy.result.Result;
import org.gnyxy.service.SearchService;
import org.gnyxy.vo.DishVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/front/search")
@Slf4j
@Api(tags = "小程序端-搜索")
public class SearchController {
    @Autowired
    private SearchService searchService;

    @GetMapping("/{name}")
    @ApiOperation("搜索联想获取name")
    public Result<Set<String>> getNameSearchName(@PathVariable String name) {
        log.info("搜索联想获取name:{}", name);
        Set<String> names = searchService.getNameSearchName(name);
        return Result.success(names);
    }

    @GetMapping("/getDish/{name}")
    @ApiOperation("搜索菜品（菜品名材料名均可）")
    public Result<Set<Dish>> getDishByName(@PathVariable String name) {
        log.info("搜索菜品（菜品名材料名均可）:{}", name);
        Set<Dish> dishes  = searchService.getDishByName(name);
        return Result.success(dishes);
    }
}
